﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace Manager.Log
{
    /// <summary>
    /// BIND log parser
    /// </summary>
    class LogParser
    {
        string m_logPath;

        /// <summary>
        /// Gets or sets the log path.
        /// </summary>
        /// <value>The log path.</value>
        public string LogPath
        {
            get { return m_logPath; }
            set { m_logPath = value; }
        }

        List<LogEntry> logEntries = new List<LogEntry>(2000);

        /// <summary>
        /// Gets the log entries.
        /// </summary>
        /// <value>The log entries.</value>
        public List<LogEntry> LogEntries
        {
            get { return logEntries; }
        }

        /// <summary>
        /// Parses the log file.
        /// </summary>
        public virtual void Parse()
        {
            using (StreamReader reader = new StreamReader(m_logPath, Encoding.Default))
            {
                while (!reader.EndOfStream)
                {
                    string line = reader.ReadLine();
                    LogEntry entry = new LogEntry();
                    entry.Date = line.Substring(0, 12);
                    entry.Time = line.Substring(13, 13);
                    entry.Information = line.Substring(26);
                    logEntries.Add(entry);
                }
            }
        }
    }
}
